package com.twu.biblioteca;

import java.io.IOException;

public class CheckOuter implements LibraryAction {

    private Library library;
    private String ACTION_NAME = "Checkout A Book";
    private IOManager ioManager;

    public CheckOuter(Library library, IOManager ioManager){
        this.library = library;
        this.ioManager = ioManager;
    }

    @Override
    public void performAction() throws IOException {
        String title = ioManager.promptUserInput("What book would you like to check out?");
        LibraryBook book = library.findBook(title);

        if (book==null)
            ioManager.print("Book title not found.");
        else{
            boolean successfulCheckOut = book.tryCheckOut();
            if (successfulCheckOut){
                ioManager.print("Thank you! Enjoy the book");
            }
            else{
                ioManager.print("That book is not available.");
            }
        }
    }

    @Override
    public String toString() {
        return ACTION_NAME;
    }

}
